﻿//隐藏窗口
function showhide(flg) {
    if (!flg) {
        ymPrompt.close();
    }
}
//添加和编辑
function $(id)
{
    return document.getElementById(id);
}
function Show(sid)
{
    if($(sid).style.display=="none")
    {
        $(sid).style.display="";
    }
    else
    {
        $(sid).style.display="none";
    }
}
function PopitFrm(url)
{
    //hidden('ddlMenu');
    //popit('形象图片',url);
    ymPrompt.win(url, 800, 600, '形象图片', null, null, null, true);
}
function FckInserImg(img)
{
    var oEditor = FCKeditorAPI.GetInstance(tmpFckEditer);
    oEditor.InsertHtml(img);
    //oEditor.EditorDocument.body.onkeyup();
} 
function PopitFckUpload(vFckName)
{
    tmpFckEditer=vFckName;
    //hidden('ddlMenu');
    //popit('上传图片','../UploadImage.aspx?t=func-obj&s=parent.FckInserImg'); 
    ymPrompt.win('../UploadImage.aspx?t=func-obj&s=parent.FckInserImg', 800, 600, '上传图片', null, null, null, true);
}
function Trim(str) 
{
    if (typeof str == 'string') return str.replace(/(^\s*)|(\s*$)/g, '');
}
function AddPic(arg)
{
    var tmppic=Trim($("txtpic").value);
    if(tmppic=="" || tmppic=="NO")
    {
        $("txtpic").value =arg;
    }
    else
    {
        var txtpicvalue=$("txtpic").value + "," + arg;
        if(txtpicvalue.length<250)
        {
            $("txtpic").value =txtpicvalue;
        }
        else
        {
            ymPrompt.errorInfo('您添加的图片字符的长度已经超过上限了！', null, null, null, null);
        }
    }
}
function ShowPic(flag)
{
    var txtpicvalue=Trim($("txtpic").value);
    var txtpicarr=txtpicvalue.split(',');
    var txtpicsrc=$("txtpicsrc");
    var surplusnum=250-txtpicvalue.length;
    if(flag)
    {
        if(txtpicvalue!="NO")
        {
            txtpicsrc.style.display="";
            var picscode="";
            var tpicscount=0;
            for(var i=0; i<txtpicarr.length;i++)
            {
                var tmpxtpic=Trim(txtpicarr[i]);
                var pic=new Image();
                pic.src=tmpxtpic;
                var picwidth=(pic.width<=340)?pic.width:340;
                if(tmpxtpic!="")
                {
                    picscode +="<img src='"+tmpxtpic+"' width='"+picwidth+"' border='1px' />";
                    tpicscount++;
                }
            }
            if(tpicscount==0)
            {
                txtpicsrc.innerHTML="您没有添加任何图片！"
            }
            else
            {
                txtpicsrc.innerHTML="您已添加"+tpicscount+"副图片了，(还可以添加"+surplusnum+"个字符！)<br />"+picscode;
            }
        }
    }
    else
    {
        txtpicsrc.style.display="none";
    }
}
function SwapMs(type)
{
    //详细模式
    if(type=="c")
    {
        SwapSelect("");
    }
    //简单模式
    else
    {
        SwapSelect("none");
    }
}
function SwapTextColor(sid)
{
    if(Trim($(sid).value)=="")
    {
        $(sid).style.backgroundColor="#cccccc";
    }
    else
    {
        $(sid).style.backgroundColor="#ffffff";
    }
}
function SwapJumpUrl()
{
    var display="";
    if($("jumpurl_on_of").checked)
    {
        display="none";
    }
    $("tr_0010").style.display=display;
}
function SwapSelect(display)
{
    var flg=$("jumpurl_on_of").checked;
    for(var i=1;i<=4;i++)
    {
        $("tr_000"+i.toString()).style.display=display;
    }
    for(var i=5;i<=9;i++)
    {
        if(!(flg && i==7))
        {
            $("tr_000"+i.toString()).style.display=display;
        }
    }  
    $("tr_0011").style.display=display;
}
//管理页面
function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
  {
    var e = form.elements[i];
    if(e.type=="checkbox")
    {
      if (e.name != "chkAll" &&　e.name != "isexact"  && e.name != "showsql" && e.disabled==false)
        e.checked = form.chkAll.checked;
    }
  }
}
function SubmitUrl()
{
    var obj = document.getElementById("ddlMenu");
    var clslist=obj.options[obj.selectedIndex].value;
    var obj2=document.getElementById("ddlTables");
    var currpostfix=obj2.options[obj2.selectedIndex].value;    
    var keyword=document.getElementById("keywords").value;   
    var isexact=document.getElementById("isexact").checked?"1":"0";
    var showsql="0"; //document.getElementById("showsql").checked?"1":"0";
    document.location.href="Admin.aspx?currpostfix="+currpostfix+"&clslist="+clslist+"&keyword="+keyword+"&isexact="+isexact+"&showsql="+showsql;
}
function SwapColor(obj,flag)
{
    if(flag)
    {
        obj.style.backgroundColor="#deeff9";
    }
    else
    {
        obj.style.backgroundColor="#f4fbff";
    }
}


//初始化下拉列表
function InitDropDownList(channels, bindclslist, seleclslist) {
    var obj = document.getElementById("ddlMenu");
    var bindflag = true;
    var bindnum = 0;
    obj.options.length = 0;

    if (channels.length > 0) {
        for (var i = 0; i < channels.length; i++) {
            if (i == 0) {
                var tOption = new Option(channels[0].text, channels[0].value);
                obj.options.add(tOption);
            }
            if (bindclslist == "" || channels[i].value.indexOf(bindclslist) == 0) {
                var oOption = new Option(channels[i].text, channels[i].value);
                oOption.style.backgroundColor = channels[i].bgcolor;
                obj.options.add(oOption);
                if (bindflag && (seleclslist == "" || channels[i].value.indexOf(seleclslist) == 0)) {
                    obj.options[bindnum].selected = "selected";
                    bindflag = false;
                }
                bindnum++;
            }
        }
    }
}
/*
<%=jsonString%>

function ChangeDropDownList() {
    var ddlobj = document.getElementById("ddlTables");
    var sarr = ddlobj.options[ddlobj.selectedIndex].value.split("-");
    if (sarr.length > 0) {
    InitDropDownList(jsonChannels, sarr[0], jsonSeleClslist);
    }
}
InitDropDownList(jsonChannels, jsonBindClslist, jsonSeleClslist);
*/
